<?php

namespace App\Http\Controllers\Api;

use App\model\BadList;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Lib\Utils\ArrayUtils;
use Lib\Utils\ModelUtils;

class BadListController extends Controller
{
    /**
     * @SWG\Post(
     *     path="/badlist/get",
     *     summary="获取菜品列表",
     *     tags={"badlist"},
     *     @SWG\Parameter(name="page",in="formData",description="页码", required=true,type="string"),
     *     @SWG\Response(
     *         response=200,
     *         description="It's ok"
     *     ),
     *     @SWG\Response(
     *         response="default",
     *         description="unexpected error"
     *     )
     * )
     */
    public function get(){
        return BadList::paginate(15);

    }
    /**
     * @SWG\Post(
     *     path="/badlist/del",
     *     summary="获取菜品列表",
     *     tags={"badlist"},
     *      @SWG\Parameter(name="id[]",in="formData",description="菜品id", required=true,type="array",@SWG\Items(type="string"), collectionFormat="multi"),
     *     @SWG\Response(
     *         response=200,
     *         description="It's ok"
     *     ),
     *     @SWG\Response(
     *         response="default",
     *         description="unexpected error"
     *     )
     * )
     */
    public function del(Request $request){
         print_r(ArrayUtils::ToArray($request->input("id")));
//        BadList::destroy(ArrayUtils::ToArray($request->input("id")));
//        return BadList::paginate(15);
    }
    /**
     * @SWG\Post(
     *     path="/badlist/save",
     *     summary="获取菜品列表",
     *     tags={"badlist"},
     *      @SWG\Parameter(name="id",in="formData",description="id", required=false,type="string"),
     *      @SWG\Parameter(name="marterial_1",in="formData",description="食材1", required=true,type="string"),
     *      @SWG\Parameter(name="marterial_2",in="formData",description="食材2", required=true,type="string"),
     *      @SWG\Parameter(name="reason",in="formData",description="原因", required=true,type="string"),
     *     @SWG\Response(
     *         response=200,
     *         description="It's ok"
     *     ),
     *     @SWG\Response(
     *         response="default",
     *         description="unexpected error"
     *     )
     * )
     */
    public function  save(Request $request){

        $form=$request->all();
        if(isset($form["id"])){
            $dish=BadList::find($form["id"]);

        }
        else{
            $dish=new BadList();

        }
        ModelUtils::requestToModel($request,$dish);
        $dish->save();
        return BadList::paginate(15);
    }
}
